package com.tmt.im.jpa.repository;

import com.tmt.data.jpa.repository.ITmtBaseRepo;
import com.tmt.im.jpa.entity.RedPackage;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;

/**
 * @Description TODO
 * @Author wuyi
 * @Date 2024/9/2 12:03
 * @Version 1.0
 **/
@Repository
public interface RedPackageRepo extends ITmtBaseRepo<RedPackage, Long> {

    @Query("select t from RedPackage t where t.creator.id =(:userId) and (:startTime is null or t.createTime >= :startTime) " +
            "and (:endTime is null or t.createTime < :endTime) order by t.createTime")
    Page<RedPackage> queryOrderByCreateTimeAscBy(@Param("userId") Long userId,
                                                 @Param("startTime") Timestamp startTime,
                                                 @Param("endTime") Timestamp endTime,
                                                 Pageable pageable);

    @Query("select t from RedPackage t where t.creator.id =(:userId) and (:startTime is null or t.createTime >= :startTime) " +
            "and (:endTime is null or t.createTime < :endTime) order by t.createTime desc")
    Page<RedPackage> queryOrderByCreateTimeDescBy(@Param("userId") Long userId,
                                                  @Param("startTime") Timestamp startTime,
                                                  @Param("endTime") Timestamp endTime,
                                                  Pageable pageable);
}
